package com.djhu.freepartner.web.control;

import com.djhu.freepartner.bean.Area;
import com.djhu.freepartner.core.RestRsp;
import com.djhu.freepartner.core.Status;
import com.djhu.freepartner.web.control.model.AreaModel;
import com.djhu.freepartner.web.service.IMetaDataService;
import com.google.gson.Gson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
@Api("字典类服务")
@Slf4j
public class MetaDataControl {

    @Autowired
    private IMetaDataService metaDataService;

    @Autowired
    private Gson gson;

    @ApiOperation(value="地区字典服务", notes="地区字典服务")
    @PostMapping("/metadata/area")
    public RestRsp area(@RequestBody AreaModel areaModel){
        log.info("area receive request is {}",gson.toJson(areaModel));
        List<Area> areas =  metaDataService.selectAreas(areaModel);
        RestRsp restRsp = new RestRsp();
        restRsp.setCode(Status.SUCCESS.getCode());
        restRsp.setData(areas);
        log.info("area return json is {}",gson.toJson(restRsp));
        return restRsp;
    }


    @ApiOperation(value="玩伴类型字典", notes="玩伴类型字典")
    @PostMapping("/metadata/playmatetype")
    public RestRsp PlaymateType(){
        List<Map<String, Object>> playtypes = metaDataService.playtypes();
        log.info("return to web playtypes is {}",playtypes);
        RestRsp restRsp = new RestRsp(Status.SUCCESS);
        restRsp.setData(playtypes);
       return restRsp;
    }

}
